home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / rpgedi1a / modres.bas < prev    next >
BASIC Source File  |  1999-08-28  |  3KB  |  116 lines

  1. Attribute VB_Name = "modRes"
  2. 'this code was obtained at planet-source-code.com and was written by ScAnFrEaK,
  3. 'with the entry name 'ChangeRes'
  4. 'it has been slightly modified
  5.  
  6. 'variables which hold the origional screen settings
  7. Public OldWidth As Single
  8. Public OldHeight As Single
  9. Public OldBPP As Integer
  10.  
  11.  
  12. Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
  13.  
  14. Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long
  15.     Private Const CCDEVICENAME = 32
  16.     Private Const CCFORMNAME = 32
  17.     Private Const DM_BITSPERPEL = &H60000
  18.     Private Const DM_PELSWIDTH = &H80000
  19.     Private Const DM_PELSHEIGHT = &H100000
  20.  
  21. Private Type DEVMODE
  22.     dmDeviceName As String * CCDEVICENAME
  23.     dmSpecVersion As Integer
  24.     dmDriverVersion As Integer
  25.     dmSize As Integer
  26.     dmDriverExtra As Integer
  27.     dmFields As Long
  28.     dmOrientation As Integer
  29.     dmPaperSize As Integer
  30.     dmPaperLength As Integer
  31.     dmPaperWidth As Integer
  32.     dmScale As Integer
  33.     dmCopies As Integer
  34.     dmDefaultSource As Integer
  35.     dmPrintQuality As Integer
  36.     dmColor As Integer
  37.     dmDuplex As Integer
  38.     dmYResolution As Integer
  39.     dmTTOption As Integer
  40.     dmCollate As Integer
  41.     dmFormName As String * CCFORMNAME
  42.     dmUnusedPadding As Integer
  43.     dmBitsPerPel As Integer
  44.     dmPelsWidth As Long
  45.     dmPelsHeight As Long
  46.     dmDisplayFlags As Long
  47.     dmDisplayFrequency As Long
  48. End Type
  49.  
  50. 'this changes the screen resolution
  51. Function ChangeRes(Width As Single, Height As Single, BPP As Integer) As Integer
  52.  
  53.     On Error GoTo ERROR_HANDLER
  54.     
  55.     Dim DevM As DEVMODE
  56.     Dim i As Integer
  57.     Dim returnVal As Boolean
  58.     Dim RetValue
  59.     
  60.     'record the origional settings
  61.     Call EnumDisplaySettings(0&, -1, DevM)
  62.  
  63.     'if the oldBPP has not yet been set
  64.     If OldBPP = 0 Then
  65.         'record the old screen settings
  66.         OldWidth = DevM.dmPelsWidth
  67.         OldHeight = DevM.dmPelsHeight
  68.         OldBPP = DevM.dmBitsPerPel
  69.     End If
  70.     i = 0
  71.  
  72.     Do
  73.         returnVal = EnumDisplaySettings(0&, i, DevM)
  74.         i = i + 1
  75.     Loop Until (returnVal = False)
  76.  
  77.     'set the devM object to the desired screen settings
  78.     DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
  79.     DevM.dmPelsWidth = Width
  80.     DevM.dmPelsHeight = Height
  81.     DevM.dmBitsPerPel = BPP
  82.     
  83.     'update the graphics mode to reflect the changes to the devM object
  84.     Call ChangeDisplaySettings(DevM, 1)
  85.     
  86.     ChangeRes = 1
  87.     Exit Function
  88.     
  89. ERROR_HANDLER:
  90.     
  91.     MsgBox "There was an error while attempting to change your display settings.", vbOKOnly + vbCritical, "RPG game"
  92.     End
  93.     
  94. End Function
  95.  
  96. 'initializes the screen
  97. Public Sub InitializeRes()
  98.  
  99. 'show the the origional screen settings have not yet been recorded
  100. OldBPP = 0
  101.     
  102.     
  103. 'change the screen to 640 x 480 x 16
  104. Call ChangeRes(640, 480, 16)
  105.  
  106. End Sub
  107.  
  108. 'restore the origional screen settings
  109. Public Sub restoreRes()
  110.  
  111. 'change the resolution back to it's origonal settings
  112. Call ChangeRes(OldWidth, OldHeight, OldBPP)
  113. End Sub
  114.  
  115.  
  116.